package wode.entity;
import jdk.nashorn.api.scripting.ScriptObjectMirror;
import wode.utils.PUtils;
import wode.view.GamePanel;

import java.awt.*;
import java.util.LinkedList;
import java.util.List;

public class EnemyPlane extends GameObject{
    List<Zidan> arrayList=new LinkedList<Zidan>();
    public static List<EnemyPlane> arrayList1=new LinkedList<EnemyPlane>();
    public static Image image1= PUtils.getImage("images/dj.png");//获取图片地址
    public static Image images=PUtils.getImage("images/zd.png");//获取图片地址
    public EnemyPlane(){
        x=300;
        y=-50;
        witdh=100;
        height=50;
        new Duogezidan().start();//创建多个子弹
    }
    @Override
    public void drawMe(Graphics g) {
        g.drawImage(image1,x,y,witdh,height,null);//画出战斗机
        y++;
        if(y>1100){y=-100;};
        for (int i = 0; i < arrayList.size(); i+=15) {
            arrayList.get(i).drawMe(g);
        }
    }
    @Override
    public Rectangle getRect() {
        return  new Rectangle(x,y,witdh,height);
    }
    class Zidan extends GameObject{
        public Zidan(){
            witdh=60;
            height=5;
        }
        @Override
        public void drawMe(Graphics g) {
            g.drawImage(images,x,y++,witdh,height,null);//画出子弹
            y++;
        }
        @Override
        public Rectangle getRect() {
            return  new Rectangle(x,y,witdh,height);
        }
    }
    class Duogezidan extends Thread{
        @Override
        public void run() {
            while (true){
                try {
                    Zidan zidan =new Zidan();
                    arrayList.add(zidan);
                    zidan.x=x+17;
                    zidan.y=y+50;
                    Thread.sleep(100);
                } catch (InterruptedException e) {
                    e.printStackTrace();
                }
            }
        }
    }
}